import axios from 'axios'
import commonUrl from '../common/js/commonUrl.js'
import qs from 'qs'
import { loadVillageId, loadUserId } from '../common/js/cache.js'

// 维护监理部分数据
// 列表数据
export function getService () {
  const url = `${commonUrl.apihost}index.php/home/Supervisor/index/?areas_id=${loadVillageId()}&user_id=${loadUserId()}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 详情数据
export function getServiceDetail (id) {
  const url = `${commonUrl.apihost}index.php/home/Supervisor/getSuperDetail/?id=${id}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 评估查验部分数据
// 列表数据
export function getsortType (type) {
  const url = `${commonUrl.apihost}index.php/home/examine/newIndex`
  const data = {
    user_id: loadUserId(),
    areas_id: loadVillageId(),
    type: type
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 第一级详情数据(post请求)
export function getCheckList (id) {
  const url = `${commonUrl.apihost}index.php/home/examine/secondIndex`
  const data = {
    id: id,
    user_id: loadUserId()
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// (get请求)
// export function getCheckList (id) {
//   const url = `${commonUrl.apihost}index.php/home/examine/secondIndex?id=${id}`
//   return axios({
//     method: 'GET',
//     url: url
//   }).then((res) => {
//     return Promise.resolve(res.data)
//   }).catch((err) => {
//     return Promise.reject(err)
//   })
// }

// 第二级详情数据
export function getCheckDetail (id, upid) {
  const url = `${commonUrl.apihost}index.php/home/examine/ThirdIndex/?id=${id}&up_id=${upid}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 请假调休数据获取管理员
export function getmanger () {
  const url = `${commonUrl.apihost}/index.php/home/employee/getadmin`
  const data = {
    areasId: loadVillageId()
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 请假调休确认提交
export function getBreaked (type, content, roleID, statTime, endTime, daynum, serverIds) {
  const url = `${commonUrl.apihost}/index.php/home/employee/setMatters`
  const data = {
    user_id: loadUserId(),
    areasId: loadVillageId(),
    type: type,
    content: content,
    role_id: roleID,
    time_start: statTime,
    time_end: endTime,
    dayNum: daynum,
    serverIds: serverIds
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 管理员审核列表信息数据
export function getExamineList () {
  const url = `${commonUrl.apihost}/index.php/home/employee/getAllMatters`
  const data = {
    user_id: loadUserId(),
    areasId: loadVillageId()
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 管理员审核详情数据
export function getExamineDetail (id) {
  const url = `${commonUrl.apihost}/index.php/home/employee/getOneMatters`
  const data = {
    mat_id: id
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 管理员审核拒绝同意按钮
export function getsetExamine (id, status) {
  const url = `${commonUrl.apihost}/index.php/home/employee/setExamine`
  const data = {
    mat_id: id,
    status: status
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 我的发起记录
export function getMyAllMatters () {
  const url = `${commonUrl.apihost}/index.php//home/employee/getMyAllMatters`
  const data = {
    user_id: loadUserId(),
    areasId: loadVillageId()
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}
